<?php
/**
 * Author:Arthur
 * Date:2013-1-31
 * File Name:reply_history_class.php
 * Email:kingarthurx@sina.cn
 */
class Reply{
	private $replyID;		//主键ID
	private $clientid;		//八优账号
	private $company_id;	//公司ID
	private $mobile;	//回复电话
	private $destmobile;	//发短信出去的号码
	private $content;	//短信回复内容
	private $time;		//回复时间
	private $msg_type;	//回复类型

	//__get()方法来获取私有属性
	public function __get($property_name) {
		if (isset ($this-> $property_name)) {
			return ($this-> $property_name);
		} else {
			return (NULL);
		}
	}
	//__set()方法用来设置私有属性
	public function __set($property_name, $value) {
		$this-> $property_name = $value;
	}
	
	
	/**
	 * 查询回复记录
	 */
	public function selectReply(){
		$sql = "SELECT DISTINCT `zy_contact`.`contact_surname`,`zy_contact`.`contact_first_name`,zy_sms_reply.* FROM zy_sms_reply 
				 LEFT JOIN `zy_contact` ON zy_sms_reply.company_id = `zy_contact`.`company_id` 
				 AND zy_sms_reply.`mobile` = `zy_contact`.`contact_mobile` where `zy_sms_reply`.`company_id`=$this->company_id ORDER BY replyID DESC  limit ".($GLOBALS['pages']-1)*$GLOBALS['displaypg'].",".$GLOBALS['displaypg'];
 		$arr=$GLOBALS['mysql']->select($sql);
	    return $arr;
	}
	/**
	 * 插入从八优服务器上取出的回复数据
	 */
	public function insertReply(){
		$sql="INSERT INTO `zy_sms_reply`(`company_id`,`clientid`,`mobile`,`destmobile`,`content`,`time`,`msg_type`) VALUES ($this->company_id,$this->clientid, $this->mobile,$this->destmobile,'$this->content','$this->time',$this->msg_type)";
		$GLOBALS['mysql']->insert($sql,false);
	}
	/**
	 * 查询短信回复记录
	 */
	public function countReplyMessageHistory(){
		$sql = "SELECT count(replyID) count FROM zy_sms_reply where company_id=$this->company_id";
 		$count=$GLOBALS['mysql']->selectId($sql);
	 	return $count->count;
	}
	/**
	 * 获取用户API 拿到用户名和密码
	 */
	public function getUserApi($str){
		if(!empty($str)){
			$sql = "select * from zy_userapi where company_id=".$str;
		}else{
			$sql = "select * from zy_userapi where company_id=".$_SESSION['user']['customer']->company_id;
		}
		$arr=$GLOBALS['mysql']->selectId($sql);
	    return $arr;
	}
	
	
}
